from flask import Flask, request
from gevent import pywsgi

app = Flask(__name__)


@app.route('/')
def hello_world():
    question = request.args.get("question")
    from langchain_community.llms import Tongyi
    import os
    # 阿里大模型：通义千问的api-key
    os.environ["DASHSCOPE_API_KEY"] = "sk-10920ad0a9d542af96353edd7ab3e613"
    llm = Tongyi()
    answer = llm.invoke(question)
    return f'我的问题是：{question}\n我的答案是：{answer}'


if __name__ == '__main__':
    server = pywsgi.WSGIServer(('127.0.0.1', 5000), app)
    server.serve_forever()
